home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Answer telephone *)
- (* *)
- (* Copyright 1989, 1990, 1991 by H. Roy Engehausen. All rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- {$O+}
-
- UNIT BBANSWER;
-
- INTERFACE
-
- USES
- bbdummy;
-
- PROCEDURE answer_modem;
- PROCEDURE connect_speed(s : str8);
-
- IMPLEMENTATION
-
- USES
- DOS,
- bbauxm,
- bbmdata,
- bbmess,
- bbmisc5,
- bbrdata,
- bbsdata,
- bbsess,
- bbsrt,
- bbstr,
- bbtask,
- bbtime,
- bbtrace,
- bbuf,
- bbwin;
-
- {$UNDEF DEBUG_1}
-
- PROCEDURE answer_modem;
-
- CONST
- time_out_other = 6;
- time_out_password = 10;
- time_out_carrier = 255;
-
- VAR
- b : BOOLEAN;
- connect_call : call_sign_str;
- i : INTEGER;
- p : STRING[4];
- s : STRING;
- uid_i_current : user_index_ptr;
-
- (*=======================================================================*)
- (* Get something from TNC *)
- (*=======================================================================*)
-
- PROCEDURE get_something;
-
- BEGIN;
-
- s := read_tnc_data_str;
-
- {$IFDEF DEBUG_1}
- trace_data('ANS1', LENGTH(s), NIL, s);
- {$ENDIF}
-
- IF s = '' THEN
- BEGIN;
- p[3] := 'T';
- window_write(p, 'Timeout on modem');
-
- cmd_tnc(@disc_cmd, TRUE);
-
- task_destroy_active;
- END;
-
- (*-------------------------------------------------------------------*)
- (* Strip leading garbage, trailing LF and upcase it *)
- (*-------------------------------------------------------------------*)
-
- WHILE (LENGTH(s) > 0) AND ((s[1] <= #$20) OR (s[1] >= #$80)) DO
- s := COPY(s, 2, 255);
-
- strip_crlf(s);
- upcase_str_var(s);
-
- {$IFDEF DEBUG_1}
- trace_data('ANS4', LENGTH(s), NIL, s);
- {$ENDIF}
-
- (*-------------------------------------------------------------------*)
- (* Check for magic NO CARRIER word *)
- (*-------------------------------------------------------------------*)
-
- IF s = no_carrier THEN
- BEGIN;
- cmd_tnc(@disc_cmd, TRUE);
- task_destroy_active;
- END;
-
- END;
-
- PROCEDURE answer_phone;
- BEGIN;
-
- send_tnc_data_str('ATA' + cr);
-
- send_flush;
-
- END;
-
- (*=======================================================================*)
- (* Main line of BBANSWER *)
- (*=======================================================================*)
-
- BEGIN;
-
- (*---------------------------------------------------------------------*)
- (* Set time out *)
- (*---------------------------------------------------------------------*)
-
- active_port^.cr_timeout := time_out_other;
-
- (*---------------------------------------------------------------------*)
- (* Change task type *)
- (*---------------------------------------------------------------------*)
-
- active_tcb^.tcb_type := th_answer;
-
- (*---------------------------------------------------------------------*)
- (* Add CRLF unless told otherwise *)
- (*---------------------------------------------------------------------*)
-
- active_port^.modem_crlf := TRUE;
-
- (*---------------------------------------------------------------------*)
- (* Initial task display *)
- (*---------------------------------------------------------------------*)
-
- STR(active_port^.com_number, p);
- active_tcb^.tcb_name := 'COM' + p;
-
- (*---------------------------------------------------------------------*)
- (* Switch window to connect *)
- (*---------------------------------------------------------------------*)
-
- active_tcb^.window := window_connect;
-
- (*---------------------------------------------------------------------*)
- (* Need to fake maxpac *)
- (*---------------------------------------------------------------------*)
-
- active_tcb^.max_pac := 250;
-
- (*---------------------------------------------------------------------*)
- (* Initialize prefix *)
- (*---------------------------------------------------------------------*)
-
- p := active_tcb^.port_chan_s + ' :';
-
- (*---------------------------------------------------------------------*)
- (* Tell LC to ignore *)
- (*---------------------------------------------------------------------*)
-
- active_tcb^.tcb_ignore_lc := TRUE;
-
- (*---------------------------------------------------------------------*)
- (* Garbage collect *)
- (*---------------------------------------------------------------------*)
-
- gc;
-
- (*---------------------------------------------------------------------*)
- (* Delay *)
- (*---------------------------------------------------------------------*)
-
- FOR i := 1 TO 8 DO
- task_switch;
-
- (*---------------------------------------------------------------------*)
- (* Loop for right number of rings *)
- (*---------------------------------------------------------------------*)
-
- i := 1;
-
- WHILE i < active_port^.answer_ring DO
- BEGIN;
-
- get_something;
-
- IF s = ring THEN
- INC(i);
-
- {$IFDEF DEBUG_1}
- trace_data('ANS5', i, NIL, s);
- {$ENDIF}
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* Answer phone *)
- (*---------------------------------------------------------------------*)
-
- answer_phone;
-
- (*---------------------------------------------------------------------*)
- (* Set timeouts for answer *)
- (*---------------------------------------------------------------------*)
-
- active_port^.cr_timeout := time_out_carrier;
-
- (*---------------------------------------------------------------------*)
- (* Delay *)
- (*---------------------------------------------------------------------*)
-
- FOR i := 1 TO 8 DO
- task_switch;
-
- (*---------------------------------------------------------------------*)
- (* Loop looking for CONNECT message from TNC *)
- (*---------------------------------------------------------------------*)
-
- REPEAT
-
- get_something;
-
- IF s = ring THEN
- answer_phone;
-
- i := words(s);
-
- {$IFDEF DEBUG_1}
- trace_data('ANS6', i, NIL, s);
- {$ENDIF}
-
- UNTIL (i <= 2) AND (subword(@s, 1, 1) = connect);
-
- (*---------------------------------------------------------------------*)
- (* Set modem speed *)
- (*---------------------------------------------------------------------*)
-
- s := subword(@s, 2, 1);
- connect_speed(s);
-
- (*---------------------------------------------------------------------*)
- (* Stop ignoring lc *)
- (*---------------------------------------------------------------------*)
-
- active_tcb^.tcb_ignore_lc := FALSE;
-
- (*---------------------------------------------------------------------*)
- (* Now that we are connected, set longer time out *)
- (*---------------------------------------------------------------------*)
-
- active_port^.cr_timeout := time_out_password;
-
- (*---------------------------------------------------------------------*)
- (* If port is locked then tell him and hang up *)
- (*---------------------------------------------------------------------*)
-
- IF active_port^.port_operate_mode.mode_stop_connect
- OR opt_block.operate_mode.mode_stop_connect THEN
- BEGIN;
- send_message(message_port_conn_off);
- end_session(TRUE);
- END;
-
- (*---------------------------------------------------------------------*)
- (* Ask for userid *)
- (*---------------------------------------------------------------------*)
-
- b := FALSE;
-
- REPEAT
-
- send_message(message_enter_uid);
- send_flush;
-
- get_something;
-
- i := words(s);
- IF (i = 1) AND (LENGTH(s) <= call_sign_len) THEN
- b := TRUE;
-
- UNTIL b;
-
- connect_call := s;
-
- {$IFDEF DEBUG_1}
- trace_data('ANS7', LENGTH(s), NIL, s);
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Find user *)
- (*---------------------------------------------------------------------*)
-
- uid_i_current := find_uid(connect_call);
-
- IF uid_i_current <> NIL THEN
- active_tcb^.uid_data := get_uid(uid_i_current)^;
-
- (*---------------------------------------------------------------------*)
- (* Ask for password *)
- (*---------------------------------------------------------------------*)
-
- i := 0;
- b := FALSE;
-
- REPEAT
-
- (*-------------------------------------------------------------------*)
- (* Bump retry count *)
- (*-------------------------------------------------------------------*)
-
- INC(i);
-
- (*-------------------------------------------------------------------*)
- (* Loop until something arrives *)
- (*-------------------------------------------------------------------*)
-
- REPEAT
-
- send_message(message_enter_password);
- send_flush;
-
- get_something;
-
- UNTIL s <> '';
-
- (*-------------------------------------------------------------------*)
- (* Bad user? *)
- (*-------------------------------------------------------------------*)
-
- IF uid_i_current = NIL THEN
- BEGIN;
- send_message(message_not_on_port);
- end_session(TRUE);
- END;
-
- (*-------------------------------------------------------------------*)
- (* Check password *)
- (*-------------------------------------------------------------------*)
-
- b := active_tcb^.uid_data.user_pw = s;
-
- (*-------------------------------------------------------------------*)
- (* Loop until password OK or retires exhausted *)
- (*-------------------------------------------------------------------*)
-
- UNTIL b OR (i > 2);
-
- (*---------------------------------------------------------------------*)
- (* Unsuccessful logon *)
- (*---------------------------------------------------------------------*)
-
- IF NOT b THEN
- BEGIN;
- send_message(message_not_on_port);
- end_session(TRUE);
- END;
-
- (*---------------------------------------------------------------------*)
- (* Now that we are fully on, reset timeouts *)
- (*---------------------------------------------------------------------*)
-
- active_port^.cr_timeout := 0;
-
- (*---------------------------------------------------------------------*)
- (* Fake a monitor connect *)
- (*---------------------------------------------------------------------*)
-
- add_mon_call(active_port, active_port^.port_char, connect_call);
-
- (*---------------------------------------------------------------------*)
- (* Now we fake a connect record from the user *)
- (*---------------------------------------------------------------------*)
-
- active_tcb^.tnc_data.str_data := t_to_h_ct + connect_call;
- active_tcb^.tnc_data.long_length :=
- LENGTH(active_tcb^.tnc_data.str_data);
-
- active_tcb^.tnc_type := t_to_h_links;
- active_tcb^.tnc_null := FALSE;
-
- active_tcb^.tcb_name := connect_call;
-
- status_window_change := TRUE;
-
- END;
-
- (*===========================================================================*)
- (* Handle the connect speed *)
- (*===========================================================================*)
-
- PROCEDURE connect_speed(s : str8);
-
- VAR
- i : WORD;
- p : STRING[4];
- speed : WORD;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Determine modem speed *)
- (*-----------------------------------------------------------------------*)
-
- IF s = '' THEN
- speed := 300
- ELSE
- BEGIN;
-
- VAL(s, speed, i);
- IF i <> 0 THEN
- BEGIN;
- p := active_tcb^.port_chan_s + 'E:';
- window_write_critical(p, 'Non numeric speed setting');
- cmd_tnc(@disc_cmd, TRUE);
- task_destroy_active;
- END;
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Set speed if this is allowed *)
- (*-----------------------------------------------------------------------*)
-
- IF NOT active_port^.modem_freez THEN
- set_port_speed(speed);
-
- (*-----------------------------------------------------------------------*)
- (* Wait for things to settle *)
- (*-----------------------------------------------------------------------*)
-
- task_wait(5, FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* Pop any waiting things off the stack *)
- (*-----------------------------------------------------------------------*)
-
- FOR speed := 1 TO 10 DO
- i := send_pending(TRUE);
-
- END;
-
- END.